package com.vben.system.api.feign.fallback;

import com.vben.common.core.util.R;
import com.vben.system.api.entity.SysUser;
import com.vben.system.api.feign.RemoteUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService> {

    @Override
    public RemoteUserService create(Throwable throwable) {
        log.error("用户服务调用失败:{}", throwable.getMessage());

        return new RemoteUserService() {

            @Override
            public R<SysUser> getUserByUsername(String username) {
                return R.failed(throwable.getMessage());
            }

            @Override
            public R<SysUser> getUserByPhone(String phone) {
                return R.failed(throwable.getMessage());
            }

            @Override
            public R<List<String>> getUserPermissionList(Long userId) {
                return R.failed(throwable.getMessage());
            }

            @Override
            public R<List<String>> getUserRoleList(Long userId) {
                return R.failed(throwable.getMessage());
            }

            @Override
            public R<Long> addUser(SysUser sysUser) {
                return R.failed(throwable.getMessage());
            }

            @Override
            public R<Boolean> updateUser(SysUser sysUser) {
                return R.failed(throwable.getMessage());
            }
        };
    }
}
